package uabc.arduino.componentes;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import uabc.arduino.monitores.Monitor;
import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class ItemSalidaPWM extends JPanel {
	private int pin;
	private Monitor monitor;
	private JSlider slider;

	public ItemSalidaPWM(String nombre, int pin, Monitor monitor) {
		setLayout(null);
		this.pin = pin;
		this.monitor = monitor;
		JLabel lblNombre = new JLabel("P" + pin + " " + nombre);
		lblNombre.setHorizontalAlignment(SwingConstants.CENTER);
		lblNombre.setBounds(0, 0, 150, 25);
		add(lblNombre);

		slider = new JSlider();
		slider.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				ItemSalidaPWM.this.monitor.ejecutarComando("4"
						+ ItemSalidaPWM.this.pin + ":" + slider.getValue());
			}
		});
		slider.setValue(0);
		slider.setMaximum(255);
		slider.setBounds(149, 0, 121, 23);
		add(slider);
	}
}